#include<bits/stdc++.h>
using namespace std;

class Solution {
public:
    int numSubarrayProductLessThanK(vector<int>& nums, int k) {
        int product = 1, i = 0, j = 0;
        int ans = 0;
        for(; j < nums.size(); j++){
            product *= nums[j];
            while(product >= k && i <= j){
                product /= nums[i++];
            }
            ans += j - i + 1;
        }
        return ans;
    }
};

/**
 * @brief 2022.5.5 
 * 滑动窗口
 * 
 */